<?php
//require_once __DIR__.'/common/common.php';

/*$str=$_SESSION['dj'];
if ($_SESSION['dj']<2||$_SESSION['dj']>20)
{
    $_SESSION['dj']=1;
}*/

/*for ($a=1;$a<=20;$a++)
{
    $sql="INSERT INTO `prize`(code) VALUES($a)";
    mysqli_query($mysql,$sql);
}
echo 'ok';*/

/*$sql="UPDATE `prize` SET winningnumber=0 ";
mysqli_query($mysql,$sql);*/
/*$sql="UPDATE `prize` SET time='0' ";
mysqli_query($mysql,$sql);*/


//$arr=range(1,20);
//var_export($arr);
/*$att=array('一等奖','二等奖','三等奖','四等奖');
for ($b=1;$b<=20;$b+=5)
{
    $i=array_rand($att,1);
    $c=rand($b,$b+4);
    $sql="UPDATE `prize` SET winningnumber='$att[$i]' WHERE uid=$c ";
    mysqli_query($mysql,$sql);
    unset ($att[$i]);
}
echo 'ok';*/


/*$sql="SELECT winningnumber FROM `prize` WHERE uid=$str";
$data=mysqli_query($mysql,$sql);
$acc=mysqli_fetch_row($data);
//var_export($acc[0]);
if ($acc[0]!=='0')
{
    $acc[0];
    $time=time();
    //$sql="UPDATE `prize` SET time='$time' WHERE uid=$str ";
    //mysqli_query($mysql,$sql);
}
$_SESSION['dj']+=1;
echo $_SESSION['dj'];*/

session_start();
$redis=new Redis();
$redis->connect(
    '127.0.0.1',
    6379
);
$redis->select(0);

if ($_SESSION['dj']<1||$_SESSION['dj']>18)
{
    $_SESSION['dj']=0;
    for ($a=1;$a<=20;$a++)
    {
        $redis->hSet('prize',$a-1,$a);
    }
    $arr=range(1,20);
    $att=array('一等奖','二等奖','三等奖','四等奖');
    for ($b=0;$b<20;$b+=5)
    {
        $i=array_rand($att,1);
        //echo $att[$i];
        $c=rand($b,$b+4);
        $redis->hSet('prize',$c,$att[$i]);
        unset ($att[$i]);
    }
}
echo $_SESSION['dj'];
$str=$_SESSION['dj'];
$att1=array('一等奖','二等奖','三等奖','四等奖');
$ss=$redis->hGet('prize',$str);
$_SESSION['dj']+=1;
if (array_search($ss,$att1)<4)
{
    echo $ss;
}

/*for ($a=1;$a<=20;$a++)
{
    $redis->hSet('prize',$a-1,$a);
}
$att=array('一等奖','二等奖','三等奖','四等奖');
for ($b=0;$b<20;$b+=5)
{
    $i=array_rand($att,1);
    echo $att[$i];
    $c=rand($b,$b+4);
    $redis->hSet('prize',$c,$att[$i]);
    unset ($att[$i]);
}*/
